// 绘制面部特征点和网格的工具函数
export const drawMesh = (predictions, ctx) => {
  if (!predictions || !ctx) return;
  
  // 绘制面部轮廓
  const faceOval = [
    10, 338, 297, 332, 284, 251, 389, 356, 454, 323, 361, 288,
    397, 365, 379, 378, 400, 377, 152, 148, 176, 149, 150, 136,
    172, 58, 132, 93, 234, 127, 162, 21, 54, 103, 67, 109
  ];
  
  // 绘制眼睛
  const leftEye = [
    33, 7, 163, 144, 145, 153, 154, 155, 133, 173, 157, 158,
    159, 160, 161, 246
  ];
  
  const rightEye = [
    362, 382, 381, 380, 374, 373, 390, 249, 263, 466, 388, 387,
    386, 385, 384, 398
  ];
  
  // 绘制嘴巴
  const mouth = [
    61, 185, 40, 39, 37, 0, 267, 269, 270, 409, 415, 310, 311,
    312, 13, 82, 81, 80, 191, 78, 62, 76, 83, 178, 84, 181, 182,
    106, 43, 57, 183, 146, 147, 211
  ];
  
  // 绘制眉毛
  const leftEyebrow = [
    336, 296, 334, 293, 300, 276, 283, 282, 295, 285
  ];
  
  const rightEyebrow = [
    70, 63, 105, 66, 107, 55, 65, 52, 53, 46
  ];
  
  // 绘制所有特征点
  predictions.scaledMesh.forEach((point, index) => {
    const [x, y, z] = point;
    
    // 根据z轴深度调整点的大小和透明度
    const size = Math.max(1, 4 - z * 0.01);
    const alpha = Math.min(1, 0.5 + z * 0.01);
    
    ctx.beginPath();
    ctx.arc(x, y, size, 0, 2 * Math.PI);
    ctx.fillStyle = `rgba(0, 255, 255, ${alpha})`;
    ctx.fill();
    
    // 标记关键特征点
    if (faceOval.includes(index)) {
      ctx.beginPath();
      ctx.arc(x, y, size + 1, 0, 2 * Math.PI);
      ctx.strokeStyle = 'rgba(255, 0, 0, 0.8)';
      ctx.lineWidth = 1;
      ctx.stroke();
    }
  });
  
  // 绘制连接线
  const drawPath = (points, color) => {
    ctx.beginPath();
    points.forEach((index, i) => {
      const [x, y] = predictions.scaledMesh[index];
      if (i === 0) {
        ctx.moveTo(x, y);
      } else {
        ctx.lineTo(x, y);
      }
    });
    ctx.strokeStyle = color;
    ctx.lineWidth = 1.5;
    ctx.stroke();
  };
  
  // 绘制各个面部特征的轮廓
  drawPath(faceOval, 'rgba(0, 255, 0, 0.7)');
  drawPath(leftEye, 'rgba(0, 0, 255, 0.7)');
  drawPath(rightEye, 'rgba(0, 0, 255, 0.7)');
  drawPath(mouth, 'rgba(255, 0, 255, 0.7)');
  drawPath(leftEyebrow, 'rgba(255, 165, 0, 0.7)');
  drawPath(rightEyebrow, 'rgba(255, 165, 0, 0.7)');
};
    